param (
    [string]$User="",
    [string]$User_pwd="",
    [string[]]$DatabasesName
)

$DATA_BACKUP_AGENT_HOME = (Get-ChildItem env:DATA_BACKUP_AGENT_HOME).Value
$Location = $DATA_BACKUP_AGENT_HOME + "\DataBackup\ProtectClient\Plugins\GeneralDBPlugin\bin\applications\exchange\ps1_scripts"
Set-Location -Path $Location
[string]$common_file_path = (Get-Location).Path + "\Common.ps1"
[string]$pssession_name = "GetDatabasesStatus"
[string]$ExchangeHost = hostname

# 引用Common.ps1
. $common_file_path

# 建立连接
if (!(NewConnection $User $User_Pwd $pssession_name)) {
    return
}

$result = @{}
foreach ($db_name in $DatabasesName) {
    $db_name_complete = $db_name + "\" + $ExchangeHost
    $db_name_complete
    $db_copystatus = Invoke-Command -Session $Session -ScriptBlock {Get-MailboxDatabaseCopyStatus -Identity $using:db_name_complete}
    if (!$?) {
        $db_status = "No exist the database: " + $db_name_complete
    } else {
        $db_status = [string]$db_copystatus.Status
    }
    $result += @{
        $db_name = $db_status
    }
}

ClosePSSession $pssession_name
$result | ConvertTo-Json -Compress -Depth 10
